"""
Python实现小型的论文查重系统
"""

python_article = "./datas/articles/Python-计算机编程语言.txt"

flask_article = "./datas/articles/Flask-PythonWeb应用框架.txt"
java_article = "./datas/articles/Java-计算编程语言.txt"
shortvideo_article = "./datas/articles/短视频-简介.txt"

import jieba.analyse


def get_keyword_from_article(fname):
	with open(fname) as fin:
		content = fin.read()
	return jieba.analyse.extract_tags(content, 50)


def compute_sim(wordsa, wordsb):
	jiaoji = set(wordsa).intersection(set(wordsb))
	bingji = set(wordsa).union(set(wordsb))
	return round(len(jiaoji) * 100 / len(bingji), 2)


python_words = get_keyword_from_article(python_article)
flask_words = get_keyword_from_article(flask_article)
java_words = get_keyword_from_article(java_article)
shortvideo_words = get_keyword_from_article(shortvideo_article)

print("python vs python", compute_sim(python_words, python_words))
print("python vs flask", compute_sim(python_words, flask_words))
print("python vs java", compute_sim(python_words, java_words))
print("python vs shortvideo", compute_sim(python_words, shortvideo_words))